function result = testEmbed(method, type, model, imgpath, rate, param1)
% TESTEMBED   embed and predict.
% RESULT = TESTEMBED(METHOD, TYPE, MODEL, IMGPATH, RATE[, PARAM1]) test
% one method 10 times on one single image.
%   MODEL is the SVM model for predict.
%   IMGPATH is the path to the image file.
% METHOD is one of the following value:
%   'none', 'jsteg', 'f3', 'f4', 'f5'.
% PARAM1 is K for 'f5', its default value is 2, and is ignored in
%   other method.
% TYPE is one of the following value:
%   '1', '2', 'all'
%
if nargin < 4
    error('testEmbed:TooFewArg', 'Too few input arguments.');
end

p = path();
path(p, ['./training' pathsep './utils' pathsep 'codec']);
REPEAT = 10;
if strcmp(method, 'none')
    class = 0;
else
    class = 1;
end

img = jpeg_read(imgpath);
[M, N] = size(img.coef_arrays{1});
switch lower(method)
    case {'none','jsteg'}
        av = countNonZeroOne(img.coef_arrays{1});
    case {'f3','f4','f5'}
        av = countNonZeroAC2(img.coef_arrays{1});
end
msglen = floor(rate*av/8);

result = zeros(REPEAT,2);
for i = 1:REPEAT
    msg = generateArray(msglen);
    start = floor(rand()*M*N);
    
    switch lower(method)
        case 'none'
            ret = img.coef_arrays{1};
        case 'jsteg'
            ret = jstege(img.coef_arrays{1}, msg, start);
        case 'f3'
            ret = f3e(img.coef_arrays{1}, msg, start);
        case 'f4'
            ret = f4e(img.coef_arrays{1}, msg, start);
        case 'f5'
            ret = f5e(img.coef_arrays{1}, param1, msg, start);
    end
    switch type
        case '1'
            h=generateHist(ret, 10);
        case '2'
            h=generateDiff2DHist(ret, 4);
        case 'all'
            h=[generateHist(ret, 10), generateDiff2DHist(ret, 4)];
    end
    [label, acc, decision_value] = svmpredict(class, h, model);
    result(i,1) = label(1,1);
    result(i,2) = decision_value(1,1);
    
    if strcmp(method,'none')
        break;
    end
end
path(p);
end

